# -*- coding=utf-8 -*-
# Author: Slp
# @Date : 2021-08-25

import os
from selenium import webdriver


class BasePage:
    # 构造函数
    def __init__(self, driver):
        self.driver = driver

    def get_chrome(self):
        chrome_path = os.path.dirname(__file__) + '/webdriver/chromedriver.exe' # 需要根据自己浏览器的版本去下载对应的文件：https://chromedriver.storage.googleapis.com/index.html
        self.driver = webdriver.Chrome(executable_path=chrome_path)
        self.driver.implicitly_wait(15)
        self.driver.maximize_window()
        return self.driver

    def get_firefox(self):
        self.driver = webdriver.Firefox()
        self.driver.implicitly_wait(15)
        self.driver.maximize_window()
        return self.driver

    # 访问URL
    def open_url(self, url):
        self.driver.get(url)


    # 退出
    def quit(self):
        self.driver.quit()

    # 元素定位，*不定长参数
    def locator(self, location):
        return self.driver.find_element(*location)

    # 输入
    def input(self, location, txt):
        self.locator(location).send_keys(txt)

    # 点击
    def click(self, location):
        self.locator(location).click()

    # 获取标题
    def get_title(self):
        return self.driver.title

    # 获取页面元素
    def get_page_source(self):
        return self.driver.page_source

    # 获取当前页面地址
    def get_current_url(self):
        return self.driver.current_url


